package com.woniuxy.movie.cinema.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.movie.cinema.dto.cinemahall.HallDto;
import com.woniuxy.movie.cinema.form.cinemahall.HallAddForm;
import com.woniuxy.movie.cinema.form.cinemahall.SelectHallForm;
import com.woniuxy.movie.cinema.form.updateStateForm;
import com.woniuxy.movie.cinema.model.CinemaHall;
import com.woniuxy.movie.cinema.service.CinemaHallService;
import com.woniuxy.movie.commons.core.model.Result;
import com.woniuxy.movie.commons.web.util.WebUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 影厅详情信息 前端控制器
 * </p>
 *
 * @author 刘存益
 * @since 2023年11月17日
 */
@RestController
@RequestMapping("/cinemaHall")
@Api(tags = "影厅相关接口")
public class CinemaHallController {

    @Autowired
    private CinemaHallService cinemaHallService;

    /**
     * 通过多个ID查询影厅信息
     * @param ids
     * @return
     */
    @PostMapping("/selIds.api")
    @ApiOperation("多个Id查询多个影厅")
    public Result<List<HallDto>> selIds(@RequestBody Set<Integer> ids){
        List<CinemaHall> cinemaHalls = cinemaHallService.listByIds(ids);
        List<HallDto> hallDtos = BeanUtil.copyToList(cinemaHalls, HallDto.class);
        return Result.getListResult(HallDto.class).setData(hallDtos);
    }

    @PostMapping("/add.api")
    @ApiOperation("新增影厅")
    public Result<String> add(@RequestBody HallAddForm form){
        cinemaHallService.add(form);
        return Result.getResult(String.class).setMsg("新增影厅成功");
    }

    @PostMapping("/select")
    @ApiOperation("查询所有影厅")
    public Result<List<CinemaHall>> select(@RequestBody SelectHallForm form){
        System.out.println(WebUtil.getRequst().getHeader("a")+"==========================");
        List<CinemaHall> cinemaHalls = cinemaHallService.select(form);
        return Result.getListResult(CinemaHall.class).setMsg("查询所有影厅成功").setData(cinemaHalls);
    }

    @PostMapping("/updateState.api")
    @ApiOperation("修改影厅状态")
    public Result<String> updateState(@RequestBody updateStateForm form){
        cinemaHallService.udpateState(form);
        return Result.getResult(String.class).setMsg("修改状态成功");
    }


    @GetMapping("/selectOne.api")
    @ApiOperation("查询单个影厅")
    public Result<CinemaHall> selectOne(Integer hallId){
        CinemaHall cinemaHall = cinemaHallService.getById(hallId);
        return Result.getResult(CinemaHall.class).setMsg("查询单个影厅信息成功").setData(cinemaHall);
    }


}

